﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ECCSystem
{
    public partial class frmDeleteHistoryData : Form
    {
        BizRule.ClsDeleteHistoryData objBRDHD;
        BizRule.ClsSystemLog objBRLog;
        public frmDeleteHistoryData()
        {
            InitializeComponent();
        }

        private void frmDeleteHistoryData_Load(object sender, EventArgs e)
        {
            dtpTo.Text = DateTime.Now.Date.ToShortDateString();
        }

        private void frmDeleteHistoryData_FormClosing(object sender, FormClosingEventArgs e)
        {
            Form frmMain = new frmMain();
            frmMain.Show();
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.CheckDate() == false)
                {
                    MessageBox.Show("終了日付は開始日付より遅い。", "ECC Information");
                    return;
                }
                if (MessageBox.Show("削除します、よろしいですか？", "ECC Information", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    int intRowsAffected = 0;
                    objBRDHD = new ECCSystem.BizRule.ClsDeleteHistoryData();
                    objBRLog = new ECCSystem.BizRule.ClsSystemLog();
                    intRowsAffected = objBRDHD.DeleteHistoryData((DateTime)dtpFrom.Value, (DateTime)dtpTo.Value);
                    MessageBox.Show("データは" + intRowsAffected + "条目削除しました。", "ECC Information");
                    objBRLog.AddSystemLog("Delete History Data!" + dtpFrom.Text + "-" + dtpTo.Text);
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "ECC Catch Error");
            }

        }

        //Check start date less than end date
        private bool CheckDate()
        {
            if (dtpFrom.Value > dtpTo.Value)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
    }
}